package com.hhxy.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * 测试获取请求行中数据的API
 * @author ghp
 * @date 2022/9/20
 */
@WebServlet("/requestLineServlet")
public class RequestLineServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取打印流对象，用于发送响应数据
        PrintWriter pw = response.getWriter();
        //设置编码格式，防止乱码
        response.setContentType("text/html;charset=utf-8");
        // 获取请求行的相关信息
        //获取请求方式
        pw.println("getMethod : " + request.getMethod() + "<br>");
        //获取资源的完整访问路径，即：URL
        pw.println("getRequestURL : " + request.getRequestURL() + "<br>");
        //获取资源的短路径（）
        pw.println("getRequestURI : " + request.getRequestURI() + "<br>");
        pw.println("getQueryString:" + request.getQueryString() + "<br>");
        pw.println("getProtocol : " + request.getProtocol() + "<br>");
        pw.println("getContextPath:" + request.getContextPath() + "<br>");
        pw.println("getPathInfo : " + request.getPathInfo() + "<br>");
        pw.println("getPathTranslated : " + request.getPathTranslated() + "<br>");
        pw.println("getSrevletPath : " + request.getServletPath() + "<br>");
        pw.println("getRemoteAddr : " + request.getRemoteAddr() + "<br>");
        pw.println("getRemoteHost : " + request.getRemoteHost() + "<br>");
        pw.println("getRemotePort : " + request.getRemotePort() + "<br>");
        pw.println("getLocalAddr : " + request.getLocalAddr() + "<br>");
        pw.println("getLocalName : " + request.getLocalName() + "<br>");
        pw.println("getLocalPort : " + request.getLocalPort() + "<br>");
        pw.println("getServerName : " + request.getServerName() + "<br>");
        pw.println("getServerPort : " + request.getServerPort() + "<br>");
        pw.println("getScheme : " + request.getScheme() + "<br>");
    }
}